#ifndef _U_BROADCAST_H
#define _U_BROADCAST_H

#include <stdint.h>

/** data max size */
#define UB_DATA_SIZE 255
/** buffer size: type(1), size(1), data(<256), checksum(1) */
#define UB_BUFFER_SIZE UB_DATA_SIZE + 3
#define UB_TYPE(msg_ptr) ((msg_ptr)->buffer[0])
#define UB_SIZE(msg_ptr) ((msg_ptr)->buffer[1])

typedef struct _uMessage {
	uint8_t buffer[UB_BUFFER_SIZE];
	uint8_t checksum;
	uint8_t *ptr;
} uMessage;

// --- Message handling ----------------------------------------
void ub_clear(uMessage * msg);
void ub_flush(uMessage * msg);
int ub_check(uMessage * msg);
int ub_cmp(uMessage * msg1, uMessage * msg2);
void ub_cpy(uMessage * dest, uMessage * src);

// --- Message write ----------------------------------------
int ub_write_char(uMessage * msg, char c);
int ub_write_str(uMessage * msq, char * str);
int ub_write_data(uMessage * msg, void * data, unsigned int size);

#endif
